package com.draven.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.draven.common.entity.NoteCategory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 笔记分类Mapper接口
 * 
 * @author draven
 */
@Mapper
public interface NoteCategoryMapper extends BaseMapper<NoteCategory> {

    /**
     * 查询分类列表（包含笔记数量）
     * 
     * @return 分类列表
     */
    @Select("SELECT c.*, COUNT(n.id) as note_count " +
            "FROM note_category c " +
            "LEFT JOIN note n ON c.id = n.category_id AND n.del_flag = 0 " +
            "WHERE c.del_flag = 0 " +
            "GROUP BY c.id " +
            "ORDER BY c.sort_order ASC, c.create_time DESC")
    List<NoteCategory> selectCategoryListWithCount();

    /**
     * 根据分类名称查询分类
     * 
     * @param categoryName 分类名称
     * @return 分类信息
     */
    @Select("SELECT * FROM note_category WHERE category_name = #{categoryName} AND del_flag = 0")
    NoteCategory selectByCategoryName(String categoryName);
}